define(function(require,exports,module){
	/**--tmpl-require--**/

	require('area');
	require('areaselect');
	require('jupload');

	
	//加载依赖
	require("ajaxproxy");
	var common = require("common");

	//初始化AjaxProxy插件
	$('.ajaxproxy').AjaxProxy({
		dataType : "json",
		method : "post",
		formId : "content-add-form",
		formCheckHandler : function(form_id) {
			return common.formCheckHandler(form_id, true);
		},
		callbackDelay : __global.jdialog.timer,
		timeInterval : __global.jdialog.timer,
		callBack : function (data) {   /* 执行ajax之后的回调函数 */
			common.ajaxCallback(data);
		}
	});

	exports.init = function(){
		/**--tmpl-todo--**/

		/**-- areaselect --**/
		selectArea({
			boxId: "addr-area",
			hasSuffix: false,
			prov:"14000000",
			city:"14010000",
			dist:"14010600"
		});
		
				/**-- baidumap --**/
					 var map = new BMap.Map("position-position");
					 map.centerAndZoom(new BMap.Point(116.328749,40.026922), 13);
					 map.enableScrollWheelZoom(true);
					 var geoc = new BMap.Geocoder();
					 map.addEventListener("click", function(e){        
						 var pt = e.point;
						 geoc.getLocation(pt, function(rs){
							 var addComp = rs.addressComponents;
							 map.clearOverlays();
							 map.centerAndZoom(rs.point, 13);
							 var marker = new BMap.Marker(rs.point);  // 创建标注
							 map.addOverlay(marker);               // 将标注添加到地图中
							 var txt = addComp.province  + addComp.city  + addComp.district  + addComp.street + addComp.streetNumber;
							 var label = new BMap.Label(txt,{offset:new BMap.Size(20,-10)});
							 marker.setLabel(label);
							 marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
							 $("input[name='data[position]']").remove();
							 $("input[name='data[positiontext]']").remove();
							 $("#position-position").after("<input type='hidden' name='data[position]' value='"+rs.point.lat + "," + rs.point.lng+"'>");
							 $("#position-position").after("<input type='hidden' name='data[positiontext]' value='"+ txt +"'>");
						 });        
					 });
					if(typeof(data) != "undefined" && data && data.position){
						pt = data.position.split(',');
						map.centerAndZoom(new BMap.Point(pt[1],pt[0]), 13);
						var marker = new BMap.Marker(new BMap.Point(pt[1],pt[0]));  // 创建标注
						map.addOverlay(marker);               // 将标注添加到地图中
						marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
				
					}
				
		/**-- picture --**/
		$("#picture-upload-idcard_positive").JUpload({
			url : exports.upload_url,
			src : "src",
			success : function(data) {
				$("#picture-input-idcard_positive").val(data);
				$("#picture-view-idcard_positive").val(data);
			}
		});
		$("#picture-preview-idcard_positive").click(function(){
			var pic = $("#picture-input-idcard_positive").val();
			if(pic){
				jpreview.load(pic);
			}
			
		});
		
		/**-- picture --**/
		$("#picture-upload-idcard_opposite").JUpload({
			url : exports.upload_url,
			src : "src",
			success : function(data) {
				$("#picture-input-idcard_opposite").val(data);
				$("#picture-view-idcard_opposite").val(data);
			}
		});
		$("#picture-preview-idcard_opposite").click(function(){
			var pic = $("#picture-input-idcard_opposite").val();
			if(pic){
				jpreview.load(pic);
			}
			
		});
		
		/**-- picture --**/
		$("#picture-upload-license_pic").JUpload({
			url : exports.upload_url,
			src : "src",
			success : function(data) {
				$("#picture-input-license_pic").val(data);
				$("#picture-view-license_pic").val(data);
			}
		});
		$("#picture-preview-license_pic").click(function(){
			var pic = $("#picture-input-license_pic").val();
			if(pic){
				jpreview.load(pic);
			}
			
		});
		
		/**-- picture --**/
		$("#picture-upload-taxno_pic").JUpload({
			url : exports.upload_url,
			src : "src",
			success : function(data) {
				$("#picture-input-taxno_pic").val(data);
				$("#picture-view-taxno_pic").val(data);
			}
		});
		$("#picture-preview-taxno_pic").click(function(){
			var pic = $("#picture-input-taxno_pic").val();
			if(pic){
				jpreview.load(pic);
			}
			
		});
		
		/**-- picture --**/
		$("#picture-upload-orgcode_pic").JUpload({
			url : exports.upload_url,
			src : "src",
			success : function(data) {
				$("#picture-input-orgcode_pic").val(data);
				$("#picture-view-orgcode_pic").val(data);
			}
		});
		$("#picture-preview-orgcode_pic").click(function(){
			var pic = $("#picture-input-orgcode_pic").val();
			if(pic){
				jpreview.load(pic);
			}
			
		});
		


	};
	/**--tmpl-otherfunction--**/
});
